package servers;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

import org.grlea.log.SimpleLogger;

public class POPServer implements IServer {

	private static final SimpleLogger log = new SimpleLogger(POPServer.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		POPServer ps = new POPServer();
		log.entry("main");
		log.exit("main");
	}

	public POPServer() {}
	
	public void listen(){
		try {
			int port = 110;
			ServerSocket srv = new ServerSocket(port);
			int i = 0;
			log.debug("starting to listen on port"+port);
			// Wait for connection from client.
			while (i++ < 2) {
				Socket socket = srv.accept();
				BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
				bw.write("+OK POP3 thats cool man\r\n");
				bw.flush();
//				bw.close();
				PopService ps = new PopService();
				ps.setSocket(socket);
				ps.run();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
